package com.dyw.application;

import com.dyw.application.bean.Cat;
import com.dyw.application.config.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @auther Devil
 * @create 2022-01-14-15:22
 */

@SpringBootApplication
public class application {
    public static void main(String[] args) {

        //返回ioc容器
        ConfigurableApplicationContext context = SpringApplication.run(application.class, args);


        //查看容器里面的组件
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }
        //指定获取容器中的组件
        Cat cat = (Cat) context.getBean("cat",Cat.class);
        String name = cat.getName();
        System.out.println(name);



        //获取配置类的在容器中的组件
        MyConfig bean = context.getBean(MyConfig.class);
        System.out.println(bean);
    }
}
